import * as API_Member from "@/api/member.js";
import { getDictByKey } from "@/libs/dictStorage";
const gradeDictData = getDictByKey("memberGrade");
const grades = {}
gradeDictData.forEach(v => {
  grades[v.dictValue] = v.dictLabel
})
export default {
  data() {
    return {
      gradeLevels: grades,
      gradeColumns: [{
          title: "会员名称",
          key: "memberName",
        },
        {
          title: "升级时间",
          key: "createDate"
        },
        {
          title: "新等级",
          key: "newGradeName"
        },
        {
          title: "旧等级",
          key: "oldGradeName"
        }
      ],
      gradeData: [], //历史等级数据
      gradeTotal: 0, //历史等级总条数
      // ta的等级
      gradeSearchForm: {
        pageNumber: 1, // 当前页数
        pageSize: 10, // 页面大小
        sort: "createTime", // 默认排序字段
        order: "desc", // 默认排序方式
      },
    }
  },
  methods: {
    //等级记录页数变化
    gradeChangePage(v) {
      this.gradeSearchForm.pageNumber = v;
      this.getDepositLogData();
    },
    //等级页数变化
    gradeChangePageSize(v) {
      this.gradeSearchForm.pageNumber = 1;
      this.gradeSearchForm.pageSize = v;
      this.getDepositLogData();
    },
    //查询TA的等级
    getGradeLog() {
      this.loading = true;
      this.gradeSearchForm.memberId = this.id;
      API_Member.getGradeLog(this.gradeSearchForm).then((res) => {
        this.loading = false;
        if (res.success) {
          res.result.records.forEach(v => {
            v.memberName = this.memberInfo.username
            v.newGradeName = this.gradeLevels[v.newGradeId]
            v.oldGradeName = this.gradeLevels[v.oldGradeId]
          })
          this.gradeData = res.result.records;
          this.gradeTotal = res.result.total;
        }
      });
      this.loading = false;
    }
  }
}